package com.gohi.main.util;

import com.gohi.main.wxapi.util.AccoutUtil;
import com.gohi.main.wxapi.vo.Token;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import com.gohi.main.store.service.ICommentService;
import com.gohi.main.store.service.IStoreService;
import com.gohi.main.system.hbm.ShopgooArea;
import com.gohi.main.system.service.ISystemService;
import com.gohi.main.util.Cache.MainCache;
import com.gohi.main.util.global.GloblConfig;
import com.gohi.main.util.task.MyTask;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import org.apache.commons.logging.LogFactory;
import org.apache.log4j.chainsaw.Main;


@SuppressWarnings("serial")
public class InitGlobalConfigServlet extends HttpServlet {

	private WebApplicationContext wac;
	//商铺
	private IStoreService storeService;
	//系统
	private ISystemService systemService;

	private static final org.apache.commons.logging.Log Log = LogFactory.getLog(InitGlobalConfigServlet.class);
	private java.util.Timer timer = null;
	@Override
	public void destroy() {
		super.destroy();
	}

	@Override
	public void init() throws ServletException {
		wac = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
		//获取网站全局的
		storeService = (IStoreService)wac.getBean("storeService");
		systemService = (ISystemService)wac.getBean("systemService");
		Log.info("正在初始化静态缓存信息.....");
		List<ShopgooArea> list =  systemService.getAre();
		MainCache.setArealist(list); //初始化区域的list
		MainCache.setBrandlist(storeService.queryAllBrand());//初始化品牌信息
		MainCache.setClasslist(storeService.getStoreClass());//获取服务分类信息
		MainCache.getBusinessmap().clear();
		MainCache.getAreaMap().clear();
		for(ShopgooArea are : list){
			//查询商圈信息
			MainCache.getBusinessmap().put(are.getArea_id(), systemService.getBusinessByareId(are.getArea_id().toString()));
			//查询级联的区域
			MainCache.getAreaMap().put(are.getArea_id(), systemService.getAreByparid(are.getArea_id().toString()));
		}
		Log.info("缓存初始化完毕..........");
		Log.info(GloblConfig.STATIC_HOST);
		

	
	}
	
}
